/*
 * BtreeNode.h
 *
 *  Created on: Oct 26, 2011
 *      Author: hxu
 */

#ifndef BTREENODE_H_
#define BTREENODE_H_
#include <ostream>

namespace Cxuh {

class BtreeNode {

public:
	BtreeNode(int id1, char nodetype);
	BtreeNode(int id1, char nodetype, int x1, int y1, int z1);
	BtreeNode(int id1, char nodetype, int x1, int y1, int z1, int z12);
	virtual ~BtreeNode();
	void setXYZ(int x1, int y1, int z1) {
		x = x1;
		y = y1;
		z = z1;
	}
	void setC(double c) {
		// input cap seen by the predecessor, excluding the children
		C = c;
	}
	void setR(double r) {
		// output res seen by the successor, excluding the parent and preceding wire
		R = r;
	}

	int getX() const {
		return x;
	}
	int getY() const {
		return y;
	}
	int getZ() const {
		return z;
	}
	virtual int getZ2() {
		return z2;
	}
	double getC() const {
		return C;
	}
	double getR() const {
		return R;
	};
	int getID() const {return id;};

	virtual double getD() const {return 0.0;};

	void calc_path_delay(); // calculate the min and max path delay
	double get_in_cload() const;	// get the c load seen at the input of this node
	char getType() const {return type;};
	void setLchild(BtreeNode * lchd);
	void setRchild(BtreeNode * rchd);
	BtreeNode* getLchild(){return lchild;};
	BtreeNode* getRchild(){return rchild;};
	BtreeNode* getParent(){return parent;};
	void setChild(BtreeNode * chd);
	void setID(int i);

	friend int operator-(const BtreeNode&, const BtreeNode&);
	friend std::ostream& operator<<(std::ostream&, BtreeNode& obj);

protected:
	int id;
	char type;
	BtreeNode* parent;
	BtreeNode* lchild, *rchild; // left and right children
	int x, y, z, z2;
	double C; // input cap seen by the predecessor, excluding the children
	double R; // output res seen by the successor, excluding the parent and preceding wire
	std::string name;
	double dmin, dmax; // the min/max delay to its sinks
	void initBtreeNode(); // initialization
	double A1, A2; // elmore delay coefficients
};

}

#endif /* BTREENODE_H_ */
